<%-- 
    Document   : profile
    Created on : 03.Nis.2010, 14:01:45
    Author     : mkafkas
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" type="text/css" href="styles/style.css" media="screen"/>
        <script src="http://static.ak.connect.facebook.com/connect.php/en_US" type="text/javascript"></script>
        <script src="js/jquery.js" type="text/javascript"></script>
        <script src="js/jquery.jqURL.js" type="text/javascript"></script>
        <script type="text/javascript">
            FB.init("696f62581a6a09ac5b17357f326fd399", "/YapmadanOlme/xd_receiver.htm" );
            FB.ensureInit(function() {
                 FB.Connect.get_status().waitUntilReady( function( status ) {
                 switch ( status ) {
                  case FB.ConnectState.connected:
                      initFunction();
                     break;
                  case FB.ConnectState.appNotAuthorized:
                  case FB.ConnectState.userNotLoggedIn:
                       // FB.Connect.requireSession();
                        window.location="index.jsp?err=You need to log in to see this page";
                  }
                });
            });

            var pic_square;
            var name;
            function initFunction() {
                var pid=$.jqURL.get('pid');
                var api=FB.Facebook.apiClient;
                api.fql_query("SELECT name,pic_big,pic_square FROM user WHERE uid="+pid,
                    function(rows){
                        $("#userImg").attr('src',rows[0].pic_big);
                        $("#userName").html(rows[0].name);
                        pic_square=rows[0].pic_square;
                        name=rows[0].name;
                        getWishList(pid);
                    });
            }
            $(document).ready(function(){
                    $(".thumpsUp").live("click",function(){
                        incrementLike(this);
                    });
                    $(".thumpsDown").live("click",function(){
                        incrementDislike(this);
                    });
                    $(".middleUpDownWantInner").live("click",function(){
                        incrementWant(this);
                        //window.alert("want to do this");
                    });
                    $(".middleUpDownDoneInner").live("click",function(){
                        incrementDone(this);
                        //window.alert("have done this");
                    });
                    $(".middleUpDownExpand").live("click",function(){
                        window.alert("expand");
                    });
            });

            function getWishList(userID)
            {
                $.post("wishes", {id:userID,type:"3"}, function(message) {
                             var arr=message.result;
                             for(var i=0;i<arr.length;i++)
                             {
                                 var newWishDiv=$(document.createElement('div')).attr('id',arr[i].wishId+"_"+arr[i].authorId).attr('class','wishItem');
                                 var currentTime = new Date((arr[i].time));
                                 var month = currentTime.getMonth() + 1;
                                 var day = currentTime.getDate();
                                 var year = currentTime.getFullYear();
                                 var hours = currentTime.getHours();
                                 var minutes = currentTime.getMinutes();
                                 if (minutes < 10){
                                    minutes = "0" + minutes;
                                 }
                                 if (hours < 10)
                                 {
                                    hours="0"+hours;
                                 }
                                 html='<div class="leftUp">'+
                                        '<img src="'+pic_square+'" alt="profile" />'+
                                    '</div>'+
                                    '<div class="middleUp">'+
                                       '<div class="middleUpUp">'+
                                            '<a href="profile.jsp?pid='+arr[i].authorID+'">'+name+'</a>'+
                                       '</div>'+
                                       '<div class="middleUpDown">'+arr[i].wish+
                                           '<div class="middleUpDownDate">'+
                                               day+'.'+month+'.'+year+'  '+hours+':'+minutes+
                                             
                                            '</div>'+
                                            '<div class="middleUpDownWant">'+
                                               '<div class="middleUpDownWantNum">'+arr[i].wantCnt+'</div>'+
                                               '<div class="middleUpDownWantInner">+ I want to do this</div>'+
                                            '</div>'+
                                            '<div class="middleUpDownDone">'+
                                                '<div class="middleUpDownDoneNum">'+arr[i].doneCnt+'</div>'+
                                                '<div class="middleUpDownDoneInner">+ I have done this</div>'+
                                            '</div>'+
                                            '<div class="middleUpDownExpand"> +Expand</div>'+
                                        '</div>'+
                                     '</div>'+
                                     '<div class="rightDown">'+
                                        '<div class="rightDownDown">'+
                                            '<div class="thumpTable">'+
                                                 '<div class="thumpTableInner">'+
                                                    '<div class="thumpsUp">'+
                                                        '<img src="images/plus.jpg" />'+
                                                    '</div>'+
                                                    '<div class="numbersUp">'+arr[i].likeCnt+'</div>'+
                                                    '<div class="thumpsDown">'+
                                                        '<img src="images/minus.jpg" />'+
                                                    '</div>'+
                                                    '<div class="numbersDown">'+arr[i].dislikeCnt+'</div>'+
                                                 '</div>'+
                                             '</div>'+
                                         '</div>'+
                                      '</div>';

                                  newWishDiv.html(html);
                                  $("#myWishList").prepend(newWishDiv);
                                  $("#"+arr[i].wishID+"_"+arr[i].authorID).hide().fadeIn(1000);
                             }
                 },"json");
            }
            function incrementLike(div)
             {
                 var wishItemDivId=$(div).parent().parent().parent().parent().parent().attr("id");
                 var wishId=wishItemDivId.split("_")[0];
                 $.post("wishes", {updateType:"1",id:wishId,type:"2"}, function(message) {
                            var likeNum=parseInt($(div).next().html());
                            $(div).next().html(likeNum+1);
                 });
             }
            function incrementDislike(div)
             {
                 var wishItemDivId=$(div).parent().parent().parent().parent().parent().attr("id");
                 var wishId=wishItemDivId.split("_")[0];
                 $.post("wishes", {updateType:"2",id:wishId,type:"2"}, function(message) {
                            var dislikeNum=parseInt($(div).next().html());
                            $(div).next().html(dislikeNum+1);
                 });
             }
            function incrementWant(div)
             {
                 var wishItemDivId=$(div).parent().parent().parent().parent().attr("id");
                 var wishId=wishItemDivId.split("_")[0];
                 $.post("wishes", {updateType:"3",id:wishId,type:"2"}, function(message) {
                            var wantNum=parseInt($(div).prev().html());
                            $(div).prev().html(wantNum+1);
                 });
             }
            function incrementDone(div)
             {
                 var wishItemDivId=$(div).parent().parent().parent().parent().attr("id");
                 var wishId=wishItemDivId.split("_")[0];
                 $.post("wishes", {updateType:"4",id:wishId,type:"2"}, function(message) {
                            var doneNum=parseInt($(div).prev().html());
                            $(div).prev().html(doneNum+1);
                 });
             }
        </script>
    </head>
    <body>
        
        <div class="profileHeaderBox" >
            <div class="profileImageBox">
                <img id="userImg" alt="imgalt"></img>
            </div>
            <div class="profileNameBox">
                <h1 id="userName" ></h1>
            </div>
        </div>
        <div id="myWishList" class="wishListContainer">
            <div class="wishItem">
                <div class="leftUp">
                    <img src="http://profile.ak.fbcdn.net/v22941/1373/64/q563383238_6681.jpg" alt="profile" />
                </div>
                <div class="middleUp">
                    <div class="middleUpUp">
                        <a href="profile.jsp?pid=563383238">Mahmut Kafkas</a>
                    </div>
                    <div class="middleUpDown">
                        soahfdhkjdaksjdaksdasjda sadhasghdashdas adsdaskljdsa
                        <div class="middleUpDownDate">
                            April 7 10:04 pm
                        </div>
                        <div class="middleUpDownWant">
                            <div class="middleUpDownWantNum">7</div>
                            <div class="middleUpDownWantInner">+ I want to do this</div>
                        </div>
                        <div class="middleUpDownDone">
                            <div class="middleUpDownDoneNum">5</div>
                            <div class="middleUpDownDoneInner">+ I have done this</div>
                            
                        </div>
                        <div class="middleUpDownExpand">
                             +Expand
                        </div>
                    </div>
                </div>
                <div class='rightDown'>
                    <div class='rightDownDown'>
                        <div class='thumpTable'>
                            <div class='thumpTableInner'>
                                <div class='thumpsUp'>
                                    <img src='images/plus.jpg' />
                                </div>
                                <div class='numbersUp'>10</div>
                                <div class='thumpsDown'>
                                    <img src='images/minus.jpg' />
                                </div>
                                <div class='numbersDown'>6</div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </body>
</html>
